package network.udp.chat;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class UdpUserA {

    public static void main(String[] args) throws IOException {

        DatagramSocket socket = new DatagramSocket(8888);
        DatagramPacket packet = null;
        String receiveData = null;
        byte[] bytes = null;

        while (true) {
            bytes = new byte[1024];
            packet = new DatagramPacket(bytes,0,bytes.length);
            socket.receive(packet);
            bytes = packet.getData();
            receiveData = new String(bytes,0, packet.getLength());
            System.out.println(receiveData);

            if (receiveData.equals("bye")) {
                break;
            }
        }

        socket.close();

    }
}
